package com.example.k8s.hello.service.sys.controller;


import cn.dev33.satoken.annotation.SaCheckPermission;
import com.example.k8s.hello.common.annotation.SysLog;
import com.example.k8s.hello.bean.sys.entity.SysConfigEntity;
import com.example.k8s.hello.bean.sys.query.SysConfigQuery;
import com.example.k8s.hello.service.sys.service.SysConfigService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import com.example.k8s.hello.common.bean.Page;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 系统配置信息
 *
 * @author Mark sunlightcs@gmail.com
 */
@RestController
@RequestMapping("/sys/config")
@Tag(name = "系统配置")
@RequiredArgsConstructor
public class SysConfigController {
	private final SysConfigService sysConfigService;
	
	/**
	 * 配置分页
	 */
	@Operation(summary = "配置分页")
	@GetMapping("/list")
	public Page list(@ParameterObject SysConfigQuery query, @ParameterObject Page page){
		return sysConfigService.queryPage(query, page);
	}
	
	
	/**
	 * 配置详情
	 */
	@Operation(summary = "配置详情")
	@GetMapping("/info/{id}")
	public SysConfigEntity info(@PathVariable("id") Long id){
		return sysConfigService.getById(id);
	}

	/**
	 * 配置详情-参数名
	 */
	@Operation(summary = "配置详情-参数名")
	@GetMapping("/info-by-key/{paramKey}")
	public SysConfigEntity infoByKey(@PathVariable("paramKey") String paramKey){
		return sysConfigService.infoByKey(paramKey);
	}
	
	/**
	 * 保存配置
	 */
	@Operation(summary = "保存配置")
	@SysLog("保存配置")
	@PostMapping("/save")
	@SaCheckPermission("sys:config:save")
	public void save(@RequestBody @Validated SysConfigEntity config){
		sysConfigService.saveConfig(config);
	}
	
	/**
	 * 修改配置
	 */
	@Operation(summary = "修改配置")
	@SysLog("修改配置")
	@PostMapping("/update")
	@SaCheckPermission("sys:config:update")
	public void update(@RequestBody @Validated SysConfigEntity config){
		sysConfigService.update(config);
	}
	
	/**
	 * 删除配置
	 */
	@Operation(summary = "删除配置")
	@SysLog("删除配置")
	@PostMapping("/delete")
	@SaCheckPermission("sys:config:delete")
	public void delete(@RequestBody Long[] ids){
		sysConfigService.deleteBatch(ids);
	}

}
